<template>
	<view class="record">
		<!-- 头部 -->
		<!-- 功能 -->
		<view class="nav">
			<view v-for="(item, index) in table" class="msg" @longtap="longtap(item)">
				<view class="msg-body">
					<view class="msg-ms">
						<view class="title">{{item.title}}</view>
						<view class="fr">{{item.publishDatetime}}</view>
					</view>
					<view class="text">{{item.content}}</view>
				</view>
			</view>
			<view v-if="table.length==0" class="none">
				<view class="none-body">
					<cover-image class="none-image" src="../../../static/images/null.png"></cover-image>
					<view class="none-text">暂无数据</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import PublicHeader from '@/components/PublicHeader.vue';
	import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';
	import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		mixins: [MescrollMixin],
		components: {
			// PublicHeader,
			MescrollBody
		},
		computed: mapState(['hasLogin', 'uerInfo']),
		data() {
			return {
				title: '我的消息',
				panduan: true, // 判断提现明细还是订单明细
				dark: true,
				downOption: {
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false
				},
				id: '',
				page: 1,
				pages: 1,
				page1: 1,
				pages1: 1,
				size: 10,
				table: [],
				list: [],
				tips: 0,
				tips1: 0,
				tips2: 0,
				type: '',
				idd: ''
			}
		},
		watch: {
			panduan() {
				this.getData()
			}
		},
		mounted() {
			var _this = this
			console.log('uerInfo:', _this.uerInfo)
			_this.id = _this.uerInfo.userId
			if (_this.uerInfo.id) {
				_this.id = _this.uerInfo.id
			}
			_this.getData()
		},
		methods: {
			getData() {
				let _this = this
				if (this.panduan) {
					if (this.table.length == 0) {
						this.page = 1
					} else {
						return
					}
					_this.$http
						.get('/user/message/list', {
							userId: _this.id,
							page: _this.page,
							size: _this.size,
							client: 'app',
							typeId: _this.type
						})
						.then(function(response) {
							if (response.success) {
								_this.table = response.data
								_this.pages = response.data.pages
							}
						}).catch(function(error) {
							console.log(error);
						});
				}
			},
			//下拉刷新的回调
			downCallback() {
				var _this = this;
				if (_this.panduan) {
					_this.page = 1,
						_this.$http
						.get('/user/message/list', {
							page: _this.page,
							size: _this.size,
							client: '用户端',
							userId: _this.id,
							typeId: _this.type
						})
						.then(function(response) {
							_this.pages = response.data.pages
							//联网成功的回调,隐藏下拉刷新的状态
							_this.table = response.data.list;
							_this.mescroll.endSuccess();
						})
						.catch(function(error) {
							console.log(error);
							_this.mescroll.endErr();
						});
				}
			},
			//上拉加载的回调
			upCallback(page) {
				var _this = this;
				if (_this.panduan) {
					if (_this.page < _this.pages) {
						_this.page = _this.page + 1;
						// _this.mescroll.endErr();
					} else {
						uni.showToast({
							icon: 'none',
							position: 'bottom',
							title: '没有更多数据啦~'
						});
						_this.mescroll.endErr();
						return
					}
					_this.$http
						.get('/user/message/list', {
							page: _this.page,
							size: _this.size,
							client: '用户端'
						})
						.then(function(response) {
							_this.pages = response.data.pages
							//设置列表数据
							_this.table = _this.table.concat(response.data.list);
							_this.mescroll.endSuccess();
						})
						.catch(function(error) {
							console.log(error);
							_this.mescroll.endErr();
						});
				}
			},
			
			longtap(e) {
				let _this = this
				console.log(e.id, "===")
				_this.idd = e.id
				uni.showModal({
					title: '提示',
					content: '请确定删除',
					success: function(res) {
						if (res.confirm) {
							_this.$http
								.get('/user/message/delete', {
									messageId: _this.idd
								})
								.then(function(res) {
									uni.showToast({
										title: '删除成功',
										duration:500
									});
									// 重新请求接口获取数据 等于刷新数据
									setTimeout(function() {
										_this.$http
											.get('/user/message/list', {
												userId: _this.id,
												page: _this.page,
												size: _this.size,
												client: 'app',
												typeId: _this.type
											})
											.then(function(response) {
												if (response.success) {
													_this.table = response.data
													_this.pages = response.data.pages
												}
											}).catch(function(error) {
												console.log(error);
											});
									}, 500)
								})
								.catch(function(error) {
									// _this.mescroll.endErr();
								});
						} else if (res.cancel) {
							
						}
					}
				});
			},
			fan(){
				var pages = getCurrentPages(); // 当前页面
				var beforePage = pages[pages.length - 2]; // 前一个页面
				setTimeout(function() {
					uni.navigateBack({
						success: function() {
							beforePage.onLoad(); // 执行前一个页面的onLoad方法
						}
					})
				}, 500)
			},
		},
		onLoad(option) {
			console.log(option.type)
			this.type = option.type
		}
	}
</script>

<style scoped lang="scss">
	page {
		/* background-color: #F9FAFB; */
	}

	.msg {
		width: 91.46%;
		/* min-height: 250rpx; */
		margin-left: 4.27%;
		margin-top: 20rpx;
		border-radius: 10rpx;
		background-color: #FFFFFF;
		border: 1rpx solid rgba(235, 236, 237, 1);
		overflow: hidden;
	}

	.card {
		width: 91.46%;
		/* min-height: 250rpx; */
		margin-left: 4.27%;
		margin-top: 20rpx;
		overflow: hidden;
		background: #EBF7FF;
		border-radius: 10px;
		border: 1px solid #BBE3FF;
	}

	.msg-body {
		width: 91.2%;
		margin-left: 4.4%;
	}
	.msg-ms{
		display: flex;justify-content: space-between;align-items: center;
	}
	.title {
		margin: 30rpx 0 10rpx 0;
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: rgba(51, 51, 51, 1);
	}

	.text {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(102, 102, 102, 1);
		padding-bottom: 15rpx;
	}
	.navv {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 90rpx;
		padding: 30rpx 30rpx 0;
		// background-color: #ffffff;
		.navone {
			image {
				width: 30rpx;
				height: 30rpx;
				color: #000000;
			}
		}
		.navtwo {
			margin: 0 auto;
			text {
				font-size: 30rpx;
				color: #333333;
			}
		}
	}
</style>
